package org.apache.ibatis;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.atomic.AtomicInteger;

public class Solution {
    public static void main(String[] args) {
        System.out.println(new Solution().minSubArrayLen(7, new int[]{2, 3, 1, 2, 4, 3}));
    }
    public int minSubArrayLen(int target, int[] nums) {
        AtomicInteger count = new AtomicInteger();
        int[] ints = Arrays.stream(nums).filter(value -> {
            if (value == target) {
                count.getAndIncrement();
            }
            return value < target;
        }).toArray();
        if (count.get() >1) {
            return 1;
        }
        if(ints.length==0|| Arrays.stream(nums).sum()<target){
            return 0;
        }
        int res = 2;
        LinkedList<Integer> list = new LinkedList<Integer>();
        for (int i = res; i <=nums.length; i++) {
            list.clear();
            for (int x = 0; x < i; x++) {
                list.add(nums[x]);
            }
            for (int j = i-1; j < nums.length; j++) {
                if (list.parallelStream().reduce(Integer::sum).orElse(0)>=target) {
                    res = Math.max(res,i);
                    return res;
                }else{
                    list.removeFirst();
                    list.add(nums[j]);
                }
            }
        }
        return 0;
    }
}
